home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-06-15 | 2.7 KB | 104 lines | [TEXT/MPS ] |
- (*
- TCPRecvChars(connectionID,count) -- Return count characters from the TCP connection.
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- pascal -w TCPRecvChars.p
- link -m ENTRYPOINT -o HyperCommands -rt XFCN=7863 -sn Main=TCPRecvChars ∂
- TCPRecvChars.p.o "{Libraries}HyperXLib.o" "{MPW}"Libraries:interface.o
-
- © Copyright 1988 by Apple Computer, Inc.
-
- Initial coding 12/88 by Harry R. Chesley.
- *)
-
- {$R-}
-
- {$S TCPRecvChars } { Segment name must be the same as the command name. }
-
- unit DummyUnit;
-
- interface
-
- uses MemTypes, QuickDraw, OSIntf, HyperXCmd;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- implementation
-
- procedure TCPRecvChars(paramPtr: XCmdPtr); forward;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- begin
- TCPRecvChars(paramPtr);
- end;
-
- procedure TCPRecvChars(paramPtr: XCmdPtr);
-
- var readCount: longInt;
- readCountStr: Str255;
- l: longInt;
- p: Ptr;
-
- procedure Fail(errMsg: Str255); { set theResult and quit }
- begin
- paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
- exit(TCPRecvChars);
- end;
-
- {$I TCPUtil.inc}
-
- begin
- if paramPtr^.paramCount <> 2 then Fail('§§§ parameter count is not 2 §§§');
-
- SetUpConnectionID;
-
- ZeroToPas(paramPtr,paramPtr^.params[2]^,readCountStr); { Second parameter is count to read. }
- readCount := StrToNum(paramPtr,readCountStr);
- if readCount < 0 then Fail('§§§ invalid count §§§');
-
- { Create the input handle. }
- paramPtr^.returnValue := NewHandle(readCount+1);
- HLock(paramPtr^.returnValue);
- { Read, read, read... }
- if readCount > 0 then
- begin
- p := paramPtr^.returnValue^;
- { First try the internal buffer. }
- with Connection^ do
- if incomingSize > 0 then
- begin
- { Read as much as there is or as much as we need, whichever is less. }
- if readCount < incomingSize then l := readCount else l := incomingSize;
- { Copy it into the result. }
- BlockMove(incomingPtr,p,l);
- incomingPtr := Ptr(ord4(incomingPtr)+l);
- incomingSize := incomingSize-l;
- p := Ptr(ord4(p)+l);
- readCount := readCount-l;
- end;
- { If there's more needed, then read it straight from the connection. }
- if readCount > 0 then
- begin
- { Issue a read (and we'll wait until it all gets in). }
- ZeroIOParms;
- SyncControlBlock.csCode := TCPcsRcv;
- PutControlLongAtOffset(ord4(p),36);
- PutControlWordAtOffset(readCount,40);
- if PBControl(@SyncControlBlock,false) <> noErr then
- begin
- HUnlock(paramPtr^.returnValue);
- disposHandle(paramPtr^.returnValue);
- Fail('§§§ receive failed §§§');
- end;
- end;
- end;
- { Tack on a zero termination byte. }
- p := ptr(ord4(paramPtr^.returnValue^)+readCount);
- p^ := 0;
- HUnlock(paramPtr^.returnValue);
- end;
-
- end.
-